<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Encore\Admin\Auth\Database\Administrator;

class AdminUserSeeder extends Seeder
{
    public function run()
    {
    	$this->setAdminUser(1, 'admin', '$2y$10$tzDRTErWuI9Dhzlfu0HDAePZj4/OFZIXAgN4g.fAA0O8dGb0PTwoK', 1);
    	$this->setAdminUser(2, 'lvzhou', '$2y$10$7y4j2ieeCOx28VzOk7ICquqV19sCtybYLBSE75I/suNOE/vNE586O', 2);
    	$this->setAdminUser(3, 'xurusheng', '$2y$10$kiR/JOhrdQGnsvDZpVxzuObJDvQ/EamJ0uE0uwPxkgBmIqSL7AR36', 3);
    	$this->setAdminUser(4, 'xiangbei', '$2y$10$.m/TbnEdpze.cF94fDFBqO0BgrzT7kBrlBf2ybZX3wZn2UoRWEkgy', 4);
	    $this->setAdminUser(27, 'lihongxuan', '$2y$10$xIz1UHII18n/3yB4wO5FQugDmP6LHp/ThdwhtB3uuukpgqLe42hd2', 1);
	    $this->setAdminUser(32, 'yangqianqian', '$2y$10$R4sGmSenjBt9/L3w4m6SGuoBkWbs9wU62wVBKjowSD/ZdQVpz17Xu', 4);
    }
    
    protected function setAdminUser($id, $name, $password, $roleId = null)
    {
	    if (!$adminUser = Administrator::query()->where('username', $name)->first()) {
		    $adminUser = Administrator::query()->create([
		    	'id' => $id,
			    'username' => $name,
			    'password' => $password,
			    'name' => ucfirst($name),
		    ]);
		    if ($roleId) {
		    	$adminUser->roles()->attach($roleId);
		    }
	    }
    }
}
